<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<textarea  style="width:100%;height:100%">


var ${ControllerName}Model = $.extend(TradeModel, {
    selRow: null, 
    editor:{
	    title: "属性",
		winid:'${ControllerName}_EditForm',
		formid:'${ControllerName}_EditForm_fm',
		width:720,
		height:300
	},  
    postAction: 'add',
    url: '/${PACKAGE}/${controllerName_LowerCase}',
    title: "标题",
    idField: "${idField}",
    titleField: "${idField}",
    toolbar: '${ControllerName}_Toolbar',
    datagrid: '${ControllerName}_Grid' 
}); 
 
${ControllerName}Model.reload =function() {
	Reload${ControllerName}List();
	$('#${ControllerName}_EditForm').dialog('close'); 
} 


function fun_FindRowById(id) {
    var cRows = $('#${ControllerName}_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][${ControllerName}Model.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}




function Show${ControllerName}EditForm(id) {  
    ${ControllerName}Model.selRow = fun_FindRowById(id);
    if (${ControllerName}Model.selRow == null) {
    	${ControllerName}Model.selRow={};
        ${ControllerName}Model.postAction = 'add';
    }
    else {
        ${ControllerName}Model.postAction = 'update';
    } 
      
    $('#${ControllerName}_EditForm_fm').form('clear' );
    $('#${ControllerName}_EditForm_fm').form('load', ${ControllerName}Model.selRow);
    $('#${ControllerName}_EditForm').dialog({
        top: "50px",
        resizable: false,
        maximizable: false 
    })
    .dialog('open')
    .dialog('setTitle', (${ControllerName}Model.postAction == 'add') ? '新增' + ${ControllerName}Model.title : '修改' + ${ControllerName}Model.selRow[${ControllerName}Model.titleField]);
}
function Save${ControllerName}() {
	${ControllerName}Model.submit();
	
}
function Del${ControllerName}( id,title) {
	${ControllerName}Model.del(id,title);
} 

function ${ControllerName}Searchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#${ControllerName}_Grid').datagrid('reload');
    }

}
 
function Reload${ControllerName}List() {
    $('#${ControllerName}_Grid').datagrid('reload');
}
 


$(function () {   
    $('#${ControllerName}_Grid').datagrid({
        pageSize: 20,
        fit: true,
        singleSelect: true,
        checkbox: false,
        rownumbers: false,
        fitColumns: true,
        pagination: true, 
        method: 'post',
        idField: ${ControllerName}Model.idField,
        treeField: ${ControllerName}Model.titleField,
        url: Onluy.basePath()+${ControllerName}Model.url+'/list',
        loader:${ControllerName}Model.Loader,
        toolbar: '#${ControllerName}_Toolbar', 
        columns: [
            [

    <#list  collist as  colum>
        <#if colum.COLUMN_COMMENT?length gt 0>
            { field: '${colum.COLUMN_NAME}', title: '${colum.COLUMN_COMMENT}', width:100, align: 'left',sortable:true },
        <#else>
            { field: '${colum.COLUMN_NAME}', title: '${ colum.COLUMN_NAME}', width:100, align: 'left',sortable:true },
        </#if>
    </#list>
			 {
					    field: 'opt', title: '操作', width: 100, align: 'center',  
					    formatter: function (value, rec) {
					        return '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/pencil.gif" onclick="Show${ControllerName}EditForm(\'' + rec[${ControllerName}Model.idField] + '\');"   />'
                                + '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/delete.gif" onclick="Del${ControllerName}(\'' + rec[${ControllerName}Model.idField] + '\',\'' + rec[${ControllerName}Model.titleField] + '\');"  />';
					    }
					} 
            ]
        ],

        
        onLoadError: function (res) {
        	${ControllerName}Model.ShowException(res); 
        },
        onLoadSuccess: function (data) {
           if(data.success){ }
           else if(data.msg){
        		 $.messager.alert('加载错误', data.msg );
        	} 
        },
        onDblClickRow: function (rowIndex, rowData) {
            Show${ControllerName}EditForm(rowData[${ControllerName}Model.idField]);
        },
        onBeforeLoad: function (param) { 
        	$('#${ControllerName}_Grid').datagrid('clearSelections');
            param['catchKey'] = Math.random();
            param['name'] = $('#${ControllerName}_ss').searchbox('getName');
            param['value'] = $('#${ControllerName}_ss').searchbox('getValue');
        }
    });
    //设置分页控件  
    var p = $('#${ControllerName}_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10  
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表  
        beforePageText: '第', //页数文本框前显示的汉字  
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



</textarea>
</body>
</html>
 